<?php

namespace App\Http\Controllers\Test;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\App;
use Pusher\Pusher;

class ActivityController extends BaseController
{
    //
    public $pusher, $username, $userid;

    public function __construct()
    {
        $app_key=getenv('PUSHER_KEY');
        $app_secret=getenv('PUSHER_SECRET');
        $app_id=getenv('PUSHER_APP_ID');
        $app_cluster=getenv('PUSHER_APP_CLUSTER');
        $this->pusher=new Pusher($app_key, $app_secret, $app_id, array( 'cluster' => $app_cluster));
        $this->username="swaggerz";
        $this->userid=1;
    }

    public function getIndex()
    {
        if(!$this->username){
            return redirect('login');
        }
        $data=[
            'text'=>$this->username.'has visited the page',
            'username'=>$this->username,
            'id'=>str_random(),
        ];

        $this->pusher->trigger('activities', 'user-visit', $data);

        return view('test.activities');
    }


    public function postStatusUpdate(Request $request)
    {
        $statusText=e($request->input('status_text'));

        $data=[
            'text'=>$statusText,
            'username'=>$this->username,
            'id' =>1
        ];

        $this->pusher->trigger('activities', 'user-visit', $data);
    }

    public function postLike($id)
    {
        $data=[
            'text'=>'...',
            'username'=>$this->username,
            'id'=>$id,
            'likedActivityId' => $id,
        ];
        $this->pusher->trigger('activities', 'new-status-update', $data);
    }





}
